/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007-2008 Intel Corporation. All Rights Reserved.
//
//
*/

#include "umc_defs.h"
#if defined(UMC_ENABLE_AVS_VIDEO_ENCODER)

#include <trace_log.h>
#include "umc_avs_enc_compressor.h"
#include "umc_avs_mb_info.h"

#include "umc_avs_enc_bit_stream.h"

namespace UMC
{

void AVSCompressor::EncodeIntraPredModeISlice(AVS_MB_INFO *pLeft,
                                              AVS_MB_INFO *pTop,
                                              Ipp32s iBlockNum)
{
    IppIntra8x8PredMode_H264 predIntraPredMode;

    // obtain prediction modes from neighbours
    if ((pLeft) && (pTop))
    {
        IppIntra8x8PredMode_H264 intraPredModeA, intraPredModeB;

        intraPredModeA = pLeft->IntraLumaPredMode[iBlockNum ^ 1];
        intraPredModeB = pTop->IntraLumaPredMode[iBlockNum ^ 2];

        predIntraPredMode = IPP_MIN(intraPredModeA, intraPredModeB);
    }
    else
        predIntraPredMode = IPP_8x8_DC;

    // calculate prediction mode encoding type
    if (m_pMbInfo->IntraLumaPredMode[iBlockNum] == predIntraPredMode)
    {
        pred_mode_flag[iBlockNum] = 1;
    }
    else
    {
        pred_mode_flag[iBlockNum] = 0;
    }

    // save prediction mode flag
    WRITE_TRACE_LOG(_enc_tst, "pred mode flag", pred_mode_flag[iBlockNum]);
    PutBit(&m_encCtx.m_stream, pred_mode_flag[iBlockNum]);

    // save prediction mode
    if (0 == pred_mode_flag[iBlockNum])
    {
        if (m_pMbInfo->IntraLumaPredMode[iBlockNum] < predIntraPredMode)
            intra_luma_pred_mode[iBlockNum] = (Ipp8s) m_pMbInfo->IntraLumaPredMode[iBlockNum];
        else
            intra_luma_pred_mode[iBlockNum] = (Ipp8s) (m_pMbInfo->IntraLumaPredMode[iBlockNum] - 1);

        // put bits to the bitstream
        WRITE_TRACE_LOG(_enc_tst, "intra luma pred mode", intra_luma_pred_mode[iBlockNum]);
        PutBits(&m_encCtx.m_stream, intra_luma_pred_mode[iBlockNum], 2);
    }

} // void AVSCompressor::EncodeIntraPredModeISlice(AVS_MB_INFO *pLeft,

Ipp32u AVSCompressor::GetSizeIntraPredModeISlice(AVS_MB_INFO *pLeft,
                                                 AVS_MB_INFO *pTop,
                                                 Ipp32s iBlockNum)
{
    IppIntra8x8PredMode_H264 predIntraPredMode;

    // obtain prediction modes from neighbours
    if ((pLeft) && (pTop))
    {
        IppIntra8x8PredMode_H264 intraPredModeA, intraPredModeB;

        intraPredModeA = pLeft->IntraLumaPredMode[iBlockNum ^ 1];
        intraPredModeB = pTop->IntraLumaPredMode[iBlockNum ^ 2];

        predIntraPredMode = IPP_MIN(intraPredModeA, intraPredModeB);
    }
    else
        predIntraPredMode = IPP_8x8_DC;

    // calculate prediction mode encoding type
    if (m_pMbInfo->IntraLumaPredMode[iBlockNum] == predIntraPredMode)
    {
        return 1;
    }
    else
    {
        return 3;
    }

} // Ipp32u AVSCompressor::GetSizeIntraPredModeISlice(AVS_MB_INFO *pLeft,

} // namespace UMC

#endif // defined(UMC_ENABLE_AVS_VIDEO_ENCODER)
